using System;
using System.Collections.Generic;
using System.Text;

namespace SIM_TPN3a
{
    public class GenVarAle
    {
        private Random oRnd;

        public GenVarAle()
        {
            oRnd = new Random();
        }
        public double DistUniforme(int a, int b)
        {
            double iRnd = oRnd.NextDouble();
            return a + iRnd * (b - a);
        }

        public double DistNormal(double media, double desv)
        {
            double iRnd1 = oRnd.NextDouble();
            double iRnd2 = oRnd.NextDouble();
            double z;
            z = Math.Sqrt(-2 * Math.Log(iRnd1)) * Math.Cos(2 * Math.PI * iRnd2);
            return media + z * desv;
        }

        public double DistExponencial(double lambda)
        {
            double iRnd = oRnd.NextDouble();
            return (-1 / lambda) * Math.Log(iRnd);
        }

        public double DistPoisson(double lambda)
        {
            int aux = 0;
            int N = 0;
            double T = 1;
            double iRnd;

            while (aux == 0)
            {
                iRnd = oRnd.NextDouble();
                T = (T * iRnd);
                if (T > Math.Exp(-lambda))
                    N = N + 1;
                else
                    aux = 1;
            }
            return N;
        }
    }
}
